package game.servlet;

import game.util.Game;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sun.istack.internal.logging.Logger;

/**
 * Servlet implementation class for the index page
 */
@WebServlet("/game")
public class GameServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final Logger logger = Logger.getLogger(Game.class);

    /**
     * @see HttpServlet#HttpServlet()
     */
    public GameServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        response.setContentType("application/json; charset=utf-8");

        session.setAttribute("name", request.getParameter("name"));
        session.setAttribute("hole", request.getParameter("hole"));
        session.setAttribute("stone", request.getParameter("stone"));

        logger.info(request.getParameter("name"));
        logger.info(request.getParameter("hole"));
        logger.info(request.getParameter("stone"));

        String destination = "game.jsp";
        response.sendRedirect(response.encodeRedirectURL(destination));
    }

}
